/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller.CoreServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.jms.Session;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.ObjectBean.RequestBean.*;
import Model.ObjectBean.ViewBean.*;
import javax.servlet.http.Cookie;
/**
 *
 * @author chickencake1
 * Function : Make an action when user logout website
 * 1. leave page
 * 2. close browser
 * 3.
 */
public class logoutServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //request.getSession().invalidate();

        LoginStatus status = new LoginStatus();
        request.getSession().setAttribute("status",status);
        status.setStatus("false");
        Cookie [] cookie = request.getCookies();
        for(int i=0;i<cookie.length;i++)
        {
            if(cookie[i].getValue().equals("logged"))
            {
                cookie[i].setValue("login");
                cookie[i].setPath("/");
                response.addCookie(cookie[i]);
            }
        }
        
                
        RequestDispatcher dispatcher= request.getRequestDispatcher("/WEB-INF/MainJSP/LoginPage.jsp");
        dispatcher.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    

    
}
